package com.starbugs.wehcat.controller;

import com.starbugs.wehcat.pojo.Student1;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.ModelMap;

@Controller
public class StudentController {

  @RequestMapping(value = "/data", method = RequestMethod.GET)
  public @ModelAttribute("user2") Student1 data(@ModelAttribute Student1 s1) {
    return new Student1().setName("huahua");
  }

  @RequestMapping(value = "/student", method = RequestMethod.GET)
  public ModelAndView student() {
    return new ModelAndView("student", "command", new Student1());
  }

  @RequestMapping(value = "/addStudent", method = RequestMethod.POST)
  public String addStudent(@ModelAttribute("SpringWeb") Student1 student,
                           ModelMap model) {
    model.addAttribute("name", student.getName());
    model.addAttribute("age", student.getAge());
    model.addAttribute("id", student.getId());
    return "result";
  }


}